﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

namespace FlightTimeCalculator
{
    public partial class Install : Page
    {
        public Install()
        {
            InitializeComponent();

            Application.Current.InstallStateChanged += new EventHandler(Current_InstallStateChanged);
        }

        void Current_InstallStateChanged(object sender, EventArgs e)
        {
            switch (Application.Current.InstallState)
            {
                case InstallState.Installed:
                    break;
                case InstallState.InstallFailed:
                    MessageBox.Show("Install failed. Please try again.", "Error", MessageBoxButton.OK);
                    break;
                case InstallState.Installing:
                    ToggleInstallLinks(false);
                    break;
                case InstallState.NotInstalled:
                    ToggleInstallLinks(true);
                    break;
            }
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.Install())
            {
                ToggleInstallLinks(false);
            }
        }

        private void ToggleInstallLinks(bool visible)
        {
            System.Windows.Visibility visibleState = (visible) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

            hyperlinkButton1.Visibility = visibleState;
        }

    }
}
